﻿
using System;
namespace RakutenCrawler.Repository
{
    public class GenreRepository:GenericRepository<Genre>
    {
        public GenreRepository():base()
        {

        }

        public GenreRepository(bool lazyLoad,bool proxyLoad):base(lazyLoad, proxyLoad)
        {

        }
        public override void InsertOrUpdate(Genre item)
        {
            var inDb = Single(t => t.GenreName == item.GenreName || item.GenreId == t.GenreId);
            if (inDb == null)
            {
                item.InsertedDate = DateTime.Now;
                All.AddObject(item);
            }
            else
            {
                if (item.GenreId == 0)
                {
                    item.GenreId = inDb.GenreId;
                    item.InsertedDate = inDb.InsertedDate;
                }

                All.ApplyCurrentValues(item);
            }
        }
    }
}
